home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / gnuplot-.5 / gnuplot- / gnuplot / term / texdraw.trm < prev    next >
Encoding:
Text File  |  1993-09-16  |  7.5 KB  |  311 lines

  1. /*
  2.  * $Id: texdraw.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - texdraw.trm */
  6. /*
  7.  * Copyright (C) 1990
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   The TEXDRAW macros for LaTeX.
  25.  *
  26.  * AUTHORS
  27.  *   Khun Yee Fung. Modified from eepic.trm.
  28.  *   clipper@csd.uwo.ca
  29.  *   January 20, 1992
  30.  *
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  *
  33.  */
  34.  
  35. /*
  36.  *  This file contains the texdraw terminal driver, intended for use with the
  37.  *  texdraw macro package for LaTeX. This is an alternative to the
  38.  *  latex driver. You need texdraw.sty, and texdraw.tex in the texdraw package.
  39.  *
  40.  */
  41.  
  42. #define TEXDRAW_PTS_PER_INCH (72.27)
  43. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  44. #define TEXDRAW_UNIT (TEXDRAW_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  45.  
  46. /* 5 inches wide by 3 inches high (default) */
  47. #define TEXDRAW_XMAX (5*DOTS_PER_INCH)
  48. #define TEXDRAW_YMAX (3*DOTS_PER_INCH)
  49.  
  50. #define TEXDRAW_HTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  51. #define TEXDRAW_VTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  52. #define TEXDRAW_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/TEXDRAW_UNIT) */
  53. #define TEXDRAW_VCHAR (DOTS_PER_INCH*11/72)    /* (11./TEXDRAW_UNIT) */
  54.  
  55. static unsigned int TEXDRAW_posx;
  56. static unsigned int TEXDRAW_posy;
  57. enum JUSTIFY TEXDRAW_justify = LEFT;
  58. enum JUSTIFY TEXDRAW_last_justify = LEFT;
  59. static int TEXDRAW_angle = 0;
  60. static float TEXDRAW_scalefactor = 0.2409;
  61. static double TEXDRAW_xscale = 1.0, TEXDRAW_yscale = 1.0;
  62.  
  63. /* for DOTS point style */
  64. #define TEXDRAW_TINY_DOT "\\htext{$\\cdot$}"
  65.  
  66. /* POINTS */
  67. #define TEXDRAW_POINT_TYPES 12    /* we supply more point types */
  68. static char GPFAR * GPFAR TEXDRAW_points[] =
  69. {
  70.   "\\rmove(0 4)\\htext{$\\Diamond$}",
  71.   "\\htext{$+$}",
  72.   "\\rmove(0 4)\\htext{$\\Box$}",
  73.   "\\htext{$\\times$}",
  74.   "\\htext{$\\triangle$}",
  75.   "\\htext{$\\star$}",
  76.   "\\lcir f:9",
  77.   "\\lcir f:12",
  78.   "\\lcir f:16",
  79.   "\\fcir f:0.9 r:9",
  80.   "\\fcir f:0.9 r:12",
  81.   "\\fcir f:0.9 r:16"
  82. };
  83.  
  84. /* LINES */
  85. #define TEXDRAW_NUMLINES 5    /* number of linetypes below */
  86. static int TEXDRAW_lines[] =
  87. {
  88.   4,        /* -2 border */
  89.   3,        /* -1 axes */
  90.   3,        /*  0 solid thin  */
  91.   4,        /*  1 solid thick */
  92.   6,        /*  2 solid Thick */
  93. };
  94.  
  95. static int TEXDRAW_last_type = 0; /* The line type selected most recently */
  96. static int TEXDRAW_type;    /* current line type */
  97. static TBOOLEAN TEXDRAW_inline = FALSE;    /* are we in the middle of a line */
  98. static void TEXDRAW_endline();    /* terminate any line in progress */
  99. static int TEXDRAW_linecount = 0;    /* number of points in line so far */
  100. #define TEXDRAW_LINEMAX 5    /* max value for linecount */
  101.  
  102. TEXDRAW_init()
  103. {
  104.   TEXDRAW_posx = TEXDRAW_posy = 0;
  105.   TEXDRAW_linetype(-1);
  106.   fprintf(outfile, "%% GNUPLOT: LaTeX using TEXDRAW macros\n");
  107. }
  108.  
  109.  
  110. TEXDRAW_scale(xs, ys)
  111. double xs, ys;            /* scaling factors */
  112. {
  113.   register struct termentry *t = &term_tbl[term];
  114.  
  115.   /* we change the table for use in graphics.c */
  116.   t->xmax = (unsigned int) (TEXDRAW_XMAX * xs);
  117.   t->ymax = (unsigned int) (TEXDRAW_YMAX * ys);
  118.  
  119.   TEXDRAW_xscale = xs;
  120.   TEXDRAW_yscale = ys;
  121.  
  122.   return (TRUE);
  123. }
  124.  
  125. TEXDRAW_graphics()
  126. {
  127. static char GPFAR tdg1[] = "\
  128. \\begin{texdraw}\n\
  129. \\normalsize\n\
  130. \\ifx\\pathDEFINED\\relax\\else\\let\\pathDEFINED\\relax\n\
  131.  \\def\\QtGfr{\\ifx (\\TGre \\let\\YhetT\\cpath\\else\\let\\YhetT\\relax\\fi\\YhetT}\n\
  132.  \\def\\path (#1 #2){\\move (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  133.  \\def\\cpath (#1 #2){\\lvec (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  134. \\fi\n\
  135. \\drawdim pt\n\
  136. \\setunitscale %2.2f\n\
  137. \\linewd %d\n\
  138. \\textref h:L v:C\n";
  139.   fprintf(outfile, tdg1, 
  140.     TEXDRAW_scalefactor,
  141.     TEXDRAW_lines[2]);
  142.   TEXDRAW_last_type = 0;
  143.   TEXDRAW_type = 0;
  144. }
  145.  
  146.  
  147. TEXDRAW_text()
  148. {
  149.   TEXDRAW_endline();
  150.   fprintf(outfile, "\\end{texdraw}\n");
  151. }
  152.  
  153.  
  154. TEXDRAW_linetype(linetype)
  155. int linetype;
  156. {
  157.   TEXDRAW_endline();
  158.  
  159.   if (linetype >= TEXDRAW_NUMLINES - 2)
  160.     linetype %= (TEXDRAW_NUMLINES - 2);
  161.  
  162.   TEXDRAW_type = linetype;
  163. }
  164.  
  165.  
  166. TEXDRAW_move(x, y)
  167. unsigned int x, y;
  168. {
  169.   TEXDRAW_endline();
  170.  
  171.   TEXDRAW_posx = x;
  172.   TEXDRAW_posy = y;
  173. }
  174.  
  175.  
  176. TEXDRAW_point(x, y, number)
  177. unsigned int x, y;
  178. int number;
  179. {
  180.   TEXDRAW_move(x, y);
  181.  
  182.   /* Print the character defined by 'number'; number < 0 means
  183.         to use a dot, otherwise one of the defined points. */
  184.   fprintf(outfile, "\\move (%d %d)\n",
  185.       (int)((double) x * TEXDRAW_xscale),
  186.       (int)((double) y * TEXDRAW_yscale));
  187.   if (TEXDRAW_last_justify != CENTRE) {
  188.     fprintf(outfile, "\\textref h:C v:C ");
  189.     TEXDRAW_last_justify = CENTRE;
  190.   }
  191.   fprintf(outfile, "%s\n",
  192.       (number < 0 ?
  193.        TEXDRAW_TINY_DOT :
  194.        TEXDRAW_points[number % TEXDRAW_POINT_TYPES]));
  195. }
  196.  
  197.  
  198. TEXDRAW_vector(ux, uy)
  199. unsigned int ux, uy;
  200. {
  201.   if (!TEXDRAW_inline) {
  202.     TEXDRAW_inline = TRUE;
  203.  
  204.     /* Start a new line. This depends on line type */
  205.     if (TEXDRAW_type != TEXDRAW_last_type){
  206.       if (TEXDRAW_lines[TEXDRAW_type+2] != TEXDRAW_lines[TEXDRAW_last_type+2])
  207.     fprintf(outfile, "\\linewd %d\n", TEXDRAW_lines[TEXDRAW_type + 2]);
  208.       TEXDRAW_last_type = TEXDRAW_type;
  209.     }
  210.     fprintf(outfile, "\\path (%d %d)",
  211.         (int)((double) TEXDRAW_posx * TEXDRAW_xscale),
  212.         (int)((double) TEXDRAW_posy * TEXDRAW_yscale));
  213.     TEXDRAW_linecount = 1;
  214.   }
  215.   else {
  216.     /* Even though we are in middle of a path,
  217.      * we may want to start a new path command.
  218.      * If they are too long then latex will choke.
  219.      */
  220.     if (TEXDRAW_linecount++ >= TEXDRAW_LINEMAX) {
  221.       fprintf(outfile, "\n\\cpath ");
  222.       TEXDRAW_linecount = 1;
  223.     }
  224.   }
  225.   fprintf(outfile, "(%d %d)",
  226.       (int)((double) ux * TEXDRAW_xscale),
  227.       (int)((double) uy * TEXDRAW_yscale));
  228.   TEXDRAW_posx = ux;
  229.   TEXDRAW_posy = uy;
  230. }
  231.  
  232. static void TEXDRAW_endline()
  233. {
  234.   if (TEXDRAW_inline) {
  235.     fprintf(outfile, "\n");
  236.     TEXDRAW_inline = FALSE;
  237.   }
  238. }
  239.  
  240.  
  241. TEXDRAW_arrow(sx, sy, ex, ey, head)
  242. int sx, sy, ex, ey;
  243. TBOOLEAN head;
  244. {
  245.   char text;
  246.  
  247.   if (head)
  248.     text = 'a';
  249.   else
  250.     text = 'l';
  251.   fprintf(outfile, "\\move (%d %d)\\%cvec (%d %d)",
  252.       (int)((double) sx * TEXDRAW_xscale),
  253.       (int)((double) sy * TEXDRAW_yscale),
  254.       text,
  255.       (int)((double) ex * TEXDRAW_xscale),
  256.       (int)((double) ey * TEXDRAW_yscale));
  257.   TEXDRAW_posx = ex;
  258.   TEXDRAW_posy = ey;
  259. }
  260.  
  261.  
  262. TEXDRAW_put_text(x, y, str)
  263. int x, y;            /* reference point of string */
  264. char str[];            /* the text */
  265. {
  266.   char text;
  267.  
  268.   TEXDRAW_endline();
  269.  
  270.   fprintf(outfile, "\\move (%d %d)",
  271.       (int)((double) x * TEXDRAW_xscale),
  272.       (int)((double) y * TEXDRAW_yscale));
  273.  
  274.   if (!TEXDRAW_angle)
  275.     text = 'h';
  276.   else
  277.     text = 'v';
  278.  
  279.   if (TEXDRAW_last_justify != TEXDRAW_justify) {
  280.     TEXDRAW_last_justify = TEXDRAW_justify;
  281.     if (TEXDRAW_justify == LEFT)
  282.       fprintf(outfile, "\\textref h:L v:C ");
  283.     else if (TEXDRAW_justify == CENTRE)
  284.       fprintf(outfile, "\\textref h:C v:C ");
  285.     else if (TEXDRAW_justify == RIGHT)
  286.       fprintf(outfile, "\\textref h:R v:C ");
  287.   }
  288.   fprintf(outfile, "\\%ctext{%s}\n", text, str);
  289. }
  290.  
  291.  
  292. int TEXDRAW_justify_text(mode)
  293. enum JUSTIFY mode;
  294. {
  295.   TEXDRAW_justify = mode;
  296.   return (TRUE);
  297. }
  298.  
  299. int TEXDRAW_text_angle(angle)
  300. int angle;
  301. {
  302.   TEXDRAW_angle = angle;
  303.   return (TRUE);
  304. }
  305.  
  306. TEXDRAW_reset()
  307. {
  308.   TEXDRAW_endline();
  309.   TEXDRAW_posx = TEXDRAW_posy = 0;
  310. }
  311.